/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GEOFENCE_NAPI_H
#define GEOFENCE_NAPI_H

#include <map>
#include <vector>

#include "napi/native_api.h"
#include "napi/native_node_api.h"

#include "geofence_callback_stub.h"
#include "geofence_data_utils.h"
#include "geofence_event.h"
#include "geofence_client.h"

namespace OHOS {
namespace Msdp {
class GeofenceCallback : public GeofenceCallbackStub{
public:
    explicit GeofenceCallback() {};
    virtual ~GeofenceCallback() {};
    void OnGeofenceChanged(const GeofenceDataUtils::GeofenceData& geofenceData) override;

private:
    // TO-DO, store latest geofence info
    // GeofenceDataUtils::GeofenceValue callbackvalue_;
};

class GeofenceNapi : public GeofenceEvent {
public:
    explicit GeofenceNapi(napi_env env, napi_value thisVar);
    virtual ~GeofenceNapi();

    static napi_value Init(napi_env env, napi_value exports);
    static void InvokeCallBack(napi_env env, napi_value *args, bool voidParameter, int32_t value);
    static napi_value SubscribePointGeofence(napi_env env, napi_callback_info info);
    static napi_value UnSubscribePointGeofence(napi_env env, napi_callback_info info);
    static napi_value SubscribePoiGeofence(napi_env env, napi_callback_info info);
    static napi_value UnSubscribePoiGeofence(napi_env env, napi_callback_info info);
    static napi_value SetFoolproofTactics(napi_env env, napi_callback_info info);
    static napi_value EnumGeofenceTypeConstructor(napi_env env, napi_callback_info info);
    static napi_value CreateEnumGeofenceType(napi_env env, napi_value exports);
    static napi_value EnumGeofenceValueConstructor(napi_env env, napi_callback_info info);
    static napi_value CreateEnumGeofenceValue(napi_env env, napi_value exports);
    static napi_value ResponseConstructor(napi_env env, napi_callback_info info);
    static napi_status AddProperty(napi_env env, napi_value object, const std::string name, int32_t enumValue);
    static napi_value CreateGeofenceValueObject(napi_env env);
    static napi_value CreateResponseClass(napi_env env, napi_value exports);
    static napi_value CreateInstanceForResponse(napi_env env, int32_t value);

    static void RegisterCallback(const int32_t& eventType);
    void OnGeofenceChangedDone(const int32_t& type, const int32_t& value, bool isOnce);
    static bool HasNamedProperty(napi_env env, napi_value object, const char *propertyName);
    static napi_value GetNamedProperty(napi_env env, napi_value object, const char *propertyName);
    //static bool MatchValueType(napi_env env, napi_value value, napi_valuetype targetType);
    //static bool MatchParamters(napi_env env, napi_value parameters[], std::initializer_list<napi_valuetype> valueTypes);
    static GeofenceNapi *GetGeofenceNapi(int32_t type);
    static std::map<int32_t, sptr<IgeofenceCallback>> callbackMap_;
    static std::map<int32_t, GeofenceNapi*> objectMap_;

private:
    napi_ref callbackRef_;
    static napi_ref geofenceValueRef_;
    napi_env env_;

};
} // namespace Msdp
} // namespace OHOS
#endif // GEOFENCE_NAPI_H
